package lp.xian.production.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lp.xian.production.vo.ReturnInfoVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.production.domain.ReturnInfo;
import lp.xian.production.service.IReturnInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退货单Controller
 *
 * @author ruoyi
 * @date 2023-07-19
 */
@RestController
@RequestMapping("/ReturnInfo/ReturnInfo")
public class ReturnInfoController extends BaseController
{
    @Autowired
    private IReturnInfoService returnInfoService;

    /**
     * 审批退货单
     */
    @PreAuthorize("@ss.hasPermi('ReturnInfo:ReturnInfo:approver')")
    @Log(title = "退货单", businessType = BusinessType.UPDATE)
    @PutMapping("/approver")
    public AjaxResult approver(@RequestBody ReturnInfoVo returnInfovo)
    {
        return toAjax(returnInfoService.approverReturnInfo(returnInfovo));
    }

    /**
     * 查询退货单列表
     */
    @PreAuthorize("@ss.hasPermi('ReturnInfo:ReturnInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReturnInfo returnInfo)
    {
        startPage();
        List<ReturnInfo> list = returnInfoService.selectReturnInfoList(returnInfo);
        return getDataTable(list);
    }

    /**
     * 导出退货单列表
     */
    @PreAuthorize("@ss.hasPermi('ReturnInfo:ReturnInfo:export')")
    @Log(title = "退货单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ReturnInfo returnInfo)
    {
        List<ReturnInfo> list = returnInfoService.selectReturnInfoList(returnInfo);
        ExcelUtil<ReturnInfo> util = new ExcelUtil<ReturnInfo>(ReturnInfo.class);
        util.exportExcel(response, list, "退货单数据");
    }

    /**
     * 获取退货单详细信息
     */
    @PreAuthorize("@ss.hasPermi('ReturnInfo:ReturnInfo:query')")
    @GetMapping(value = "/{returnId}")
    public AjaxResult getInfo(@PathVariable("returnId") Integer returnId)
    {
        return success(returnInfoService.selectReturnInfoByReturnId(returnId));
    }

    /**
     * 新增退货单
     */
    @PreAuthorize("@ss.hasPermi('ReturnInfo:ReturnInfo:add')")
    @Log(title = "退货单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReturnInfo returnInfo)
    {
        return toAjax(returnInfoService.insertReturnInfo(returnInfo));
    }

    /**
     * 修改退货单
     */
    @PreAuthorize("@ss.hasPermi('ReturnInfo:ReturnInfo:edit')")
    @Log(title = "退货单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReturnInfo returnInfo)
    {
        return toAjax(returnInfoService.updateReturnInfo(returnInfo));
    }

    /**
     * 删除退货单
     */
    @PreAuthorize("@ss.hasPermi('ReturnInfo:ReturnInfo:remove')")
    @Log(title = "退货单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{returnIds}")
    public AjaxResult remove(@PathVariable Integer[] returnIds)
    {
        return toAjax(returnInfoService.deleteReturnInfoByReturnIds(returnIds));
    }
}
